package com.hulk.ratel.common.security;

import lombok.AccessLevel;
import lombok.Value;
import lombok.experimental.FieldDefaults;
import lombok.experimental.UtilityClass;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;


/**
 * @author hulk
 * @E-mail:29572320@qq.com
 * @version Create on:  2017年4月28日 上午8:51:42
 * Class description
 */

@UtilityClass
@Value
@FieldDefaults(level = AccessLevel.PRIVATE)
public class AesSeedKey {

       String SEED = "SEED";
       String ALGORITHM = "AES";


    private  SecretKey geneAesKey() {
        KeyGenerator keyGenerator = null;
        SecureRandom random = null;
        try {
            keyGenerator = KeyGenerator.getInstance(ALGORITHM);
            random = SecureRandom.getInstance("SHA1PRNG");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }


        random.setSeed(SEED.getBytes());
        keyGenerator.init(128, random);
        SecretKey secretKey = keyGenerator.generateKey();
        return secretKey;
    }


}
